export const state=()=>(
    {
      userInfo: {
        token: '',
        user: {}
      },
    }
)

export const mutations={
    setUserInfo(state,data){
        state.userInfo=data
    },
}
export const actions={
  //登录
    login(store,data) {   
        return this.$axios({
          url: '/accounts/login',
          method: 'post',
          data,
        }).then(res => {
          // console.log(res.data);
          store.commit('setUserInfo', res.data);
         
        })
    },
    // 注册
    register(store, data) {
        return this.$axios({
          url: '/accounts/register',
          method: 'post',
          data,
        }).then(res => {
        store.commit('setUserInfo', res.data);            
        //   console.log(res.data)
        })
    },
  //  发送验证码，tel电话号码
    captcha(store,tel){
        return this.$axios({
          url: `/captchas`,
          method: "POST",
          data: {
            tel,
          }
        }).then(res => {
          const { code} = res.data;
          return code
        })
    }
}